package com.whksoft.mymapplugin.Listener;

import com.whksoft.mymapplugin.API.Event.MapClearedEvent;
import com.whksoft.mymapplugin.API.Event.PaymentCanceledEvent;
import com.whksoft.mymapplugin.utils.CancelReason;
import com.whksoft.mymapplugin.utils.itemUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.plugin.Plugin;

/**
 * 检测玩家打开交互界面
 */
public class openInv implements Listener {

    Plugin plugin;

    public openInv(Plugin plugin) {
        this.plugin = plugin;
    }

    //打开工作台 制图台 锻造台 熔炉 漏斗 箱子 陷阱箱 马 羊驼 漏斗矿车 村民 酿造台等界面的时候会取消支付（E除外）
    @EventHandler(priority = EventPriority.HIGHEST)
    public void invOpen(InventoryOpenEvent e) {
        itemUtils.clearMaps((Player) e.getPlayer());
        Bukkit.getPluginManager().callEvent(new MapClearedEvent((Player) e.getPlayer()));
        Bukkit.getPluginManager().callEvent(new PaymentCanceledEvent((Player) e.getPlayer(), CancelReason.OPEN_INV));
    }
}
